package com.itheima.homework9;

import java.util.Random;
import java.util.Scanner;

public class YanZhenMa {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //拼接一个大字符串,包含[a-z,A-Z,0-9]
        //String s1 = new String();
        StringBuilder s1  =new StringBuilder("0123456789");
        for (char i = 'a', j = 'A'; i <= 'z' && j <= 'Z'; i++, j++) {
            s1.append(i).append(j);
        }

        Random ra = new Random();

        while (true) {
            //定义一个字符串接收验证码
            String st = new String();
            for (int i = 1; i <= 4; i++) {
                int index = ra.nextInt(s1.length());
                char c = s1.charAt(index);
                st += c;
            }
            System.out.println("生成验证码:" + st);
            System.out.println("请输入验证码:");
            String s = sc.nextLine();
            if (s.equalsIgnoreCase(st)) {
                System.out.println("输入正确");
                break;
            } else {
                System.out.println("输入错误，请重新输入...");
            }
        }

    }
}
